package com.interfaces;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.entity.Sysdic;

/**
 * @Title: SysdicDao.java
 * @Package com.interfaces
 * @author 孙梦楠
 * @date 2017年7月19日 下午4:42:02
 * @version V1.0.0
 */

public interface SysdicDao extends JpaRepository<Sysdic, Integer> {

	// 通过中文查实际值
	Sysdic findBySysdicdisplay(String sysdicdisplay);

	// 通过value值查单条
	@Transactional
	@Query(value = "SELECT s FROM Sysdic s WHERE s.sysdictype=?1 AND s.sysdicvalue =?2 AND s.sysdicisdel=0")
	Sysdic findBySysdictypeAndSysdicvalue(String sysdictype, String sysdicvalue);

	@Transactional
	@Query(value = "SELECT s FROM Sysdic s WHERE s.sysdictype=?1 AND s.sysdicisdel=0")
	public List<Sysdic> findBySysdictype(String sysdictype);

	// 通过type倒叙排序
	List<Sysdic> findBySysdictypeOrderBySysdicordDesc(String sysdictype);

	@Transactional
	@Query(value = "SELECT * FROM e_sysdic s WHERE s.sysdic_type LIKE '0%' AND s.sysdic_isdel = '0' "
			+ "ORDER BY s.sysdic_type , s.sysdic_ord", nativeQuery = true)
	public List<Sysdic> listsys();

	// 修改字典状态
	@Transactional
	@Modifying
	@Query("update Sysdic s set s.sysdicisdel = ?1 where s.sysdicid=?2")
	int updateSysdicisdel(Byte sysdicisdel, Integer sysdicid);
	
	@Transactional
	@Query(value = "SELECT s FROM Sysdic s WHERE s.sysdictype=?1")
	public List<Sysdic> findBySysdictype2(String sysdictype);

	
	
}
